package com.ma.reportForm;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.ma.R;

import java.util.ArrayList;
import java.util.List;

import base.BaseActivity;
import lomasky.xui.BaseViewHolderForListView;
import lomasky.xui.CommonAdapter;
import lomasky.xui.NoScrollGridView;

public class OccupancyAnalzeActivity extends BaseActivity {

    private NoScrollGridView mIconGroup1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_occupancy_analze);
        initView();
        initView1();
    }

    private void initView() {
        mIconGroup1 = (NoScrollGridView) findViewById(R.id.icon_group1);

    }

    private void initView1() {


        List<DataBean> list = new ArrayList<>();
        list.add(new DataBean("总户数", "250"));
        list.add(new DataBean("已入住", "50"));
        list.add(new DataBean("未入住", "10"));
        list.add(new DataBean("已出租", "50"));
        list.add(new DataBean("已装修", "160"));

        list.add(new DataBean("", ""));
        list.add(new DataBean("", ""));
        list.add(new DataBean("", ""));


        CommonAdapter<DataBean> adapter = new CommonAdapter<DataBean>(this, list, R.layout.collect_fees_bottom_item1) {
            @Override
            public void convert(BaseViewHolderForListView helper, DataBean item, int position) {


                if (TextUtils.isEmpty(item.text)) {
                    helper.getTextView(R.id.money).setBackgroundResource(R.drawable.transparent);
                    helper.setText(R.id.money, "");
                    helper.setText(R.id.text, "");


                } else {


                    helper.setText(R.id.text, item.text);
                    helper.setText(R.id.money, item.money);


                    if (item.isCheck) {
                        helper.getTextView(R.id.money).setTextColor(getResources().getColor(R.color.white));
                        helper.getTextView(R.id.text).setTextColor(getResources().getColor(R.color.colorPrimary));
                        helper.getTextView(R.id.money).setBackgroundResource(R.drawable.bound_bg2);

                    } else {
                        helper.getTextView(R.id.money).setTextColor(getResources().getColor(R.color.colorPrimary));
                        helper.getTextView(R.id.text).setTextColor(getResources().getColor(R.color.dark));
                        helper.getTextView(R.id.money).setBackgroundResource(R.drawable.bound_bg1);
                    }

                    if (position == 0 || position == 7 || position == 5 || position == 6) {

                        helper.getTextView(R.id.money).setBackgroundResource(R.drawable.bound_bg3);
                        helper.getTextView(R.id.text).setTextColor(getResources().getColor(R.color.dark));
                        helper.getTextView(R.id.money).setTextColor(getResources().getColor(R.color.dark));
                    }
                }


            }
        };

        mIconGroup1.setOnItemClickListener((adapterView, view, position, l) -> {

            if (position == 0 || position == 7 || position == 5 || position == 6) {
                return;
            }

            for (int i = 0; i < list.size(); i++) {

                list.get(i).setCheck(i == position);


            }
            adapter.setList(list);
            adapter.notifyDataSetChanged();


        });


        mIconGroup1.setAdapter(adapter);

    }

    public void showDialog(View view) {

        new ChooseProjectDialog(this).show();
    }

    class DataBean {
        public String text;
        public String money;
        public boolean isCheck;

        public DataBean(String text1, String text2) {
            this.text = text1;
            this.money = text2;
        }

        public boolean isCheck() {
            return isCheck;
        }

        public void setCheck(boolean check) {
            isCheck = check;
        }

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }
    }
}
